﻿#include "stdafx.h"
#include "FileDlgUtil.h"
#include <windows.h>  
#include <Commdlg.h>  


FileDlgUtil::FileDlgUtil(void)
{
}


FileDlgUtil::~FileDlgUtil(void)
{
}


BOOL FileDlgUtil::OpenPcmFile(std::wstring &strPath)  
{   
    TCHAR szPathName[MAX_PATH] = {0};  
    OPENFILENAME ofn = { OPENFILENAME_SIZE_VERSION_400 };//or  {sizeof (OPENFILENAME)}    
    ofn.hwndOwner = GetForegroundWindow();
    ofn.lpstrFilter = TEXT("pcm文件(*.wav)\0*.*\0\0");  
    ofn.lpstrFile = szPathName;
    ofn.nMaxFile = sizeof(szPathName);
    ofn.lpstrTitle = TEXT("选择文件");
    ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST;  
  
    BOOL bOk = GetOpenFileName(&ofn);
    if (!bOk)    
    {    
        return FALSE;  
    }   
    std::wcout.imbue(std::locale("chs"));  
    std::wcout << L"选择文件: " << szPathName << std::endl;  
    strPath = szPathName;  
  
    return TRUE;  
}  


BOOL FileDlgUtil::SavePcmFile(std::wstring &strPath)  
{  
    wchar_t szPathName[MAX_PATH] = {0};  
    OPENFILENAME ofn = { OPENFILENAME_SIZE_VERSION_400 };//or  {sizeof (OPENFILENAME)}    
    ofn.hwndOwner = GetForegroundWindow();
    wcscpy_s(szPathName, TEXT("new.pcm"));
    ofn.lpstrFilter = TEXT("Pcm文件(*.wav)\0*.*\0\0");  
    ofn.lpstrFile = szPathName;  
    ofn.nMaxFile = sizeof(szPathName);  
    ofn.lpstrTitle = TEXT("保存文件");  
    ofn.Flags = OFN_OVERWRITEPROMPT;
  
    BOOL bOk = GetSaveFileName(&ofn);  
    if (!bOk)  
    {  
        return FALSE;  
    }  
    std::wcout.imbue(std::locale("chs"));  
    std::wcout << L"保存文件: " << szPathName << std::endl;  
      
    strPath = szPathName;  
  
    return TRUE;  
}